cmake_minimum_required(VERSION 3.28)
project(untitled1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 设置Qt安装路径
set(CMAKE_PREFIX_PATH "D:/software/Qt6.7/6.7.1/mingw_64")

find_package(Qt6 COMPONENTS QuickControls2)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Quick Qml)

add_executable(untitled1
        main.cpp
        qresource.qrc
        resources/icon/icon.rc
)

target_link_libraries(untitled1
        PRIVATE Qt6::Core
        PRIVATE Qt6::Gui
        PRIVATE Qt6::Widgets
        PRIVATE Qt6::Quick
        PRIVATE Qt6::Qml
        PRIVATE Qt6::QuickControls2
)

# 复制必要的Qt DLL文件
if (WIN32)
    set(DEBUG_SUFFIX)
    if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    foreach (QT_LIB Core Gui Widgets Quick Qml)
        add_custom_command(TARGET untitled1 POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt6${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:untitled1>")
    endforeach ()
endif ()
